<template>
	<view class="content">
		<view class="c1" style="width: 90%;margin:0 auto">
			<uni-forms ref="form" :modelValue="paymentType" :rules="rules">
				<uni-forms-item label="类型" name="type" required>
					<uni-easyinput type="text" v-model="paymentType.type" placeholder="请输入缴费类型" />
				</uni-forms-item>
				<uni-forms-item label="收款方" name="payee" required>
					<uni-easyinput type="text" v-model="paymentType.payee" placeholder="请输入收款方" />
				</uni-forms-item>
				<uni-forms-item label="账单名称" name="billName" required>
					<uni-easyinput type="text" v-model="paymentType.billName" />
				</uni-forms-item>
				<uni-forms-item label="账单编号" name="billNumber" required>
					<uni-easyinput type="text" v-model="paymentType.billNumber" placeholder="请输入账单编号" />
					<button @click="dianji" class="dd">点击生成账单号</button>
				</uni-forms-item>

				<uni-forms-item label="金额" name="money" required>
					<uni-easyinput type="text" v-model="paymentType.money" placeholder="请输入基础金额" />
				</uni-forms-item>

			</uni-forms>
			<u-line color="#2979ff"></u-line>
			<u-button class="button-login" type="primary" @click="submitForm" hover-class="button-hover">
				下一步</u-button>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				elevatorshow: false,
				flag: true,
				loading: false,
				tabList: [],
				token: '',
				name: '',
				hobby: '男',
				paymentType: {
					userId: uni.getStorageSync('loginData').user_id,
					houseId: '',
					payee: '',
					chargeId: '',
					payee: '',
					house_model: '',
					money: '',
					floor: '',
					otherMoney: '',
					money: '',
					begintime: '',
					payDay: '',
					billNumber: '',
					type: '',
					billType: '未付',
					payee: '',
					account: ''
				},
				rules: {
					billName: {
						rules: [{
							required: true,
							errorMessage: '请输入账单名称',
						}, ]
					},
					payee: {
						rules: [{
							required: true,
							errorMessage: '请输入收款方',
						}, ]
					},
					billNumber: {
						rules: [{
							required: true,
							errorMessage: '请输入基础账单编号',
						}, ]
					},
					money: {
						rules: [{
							required: true,
							errorMessage: '请输入金额',
						}, ]
					},
					type: {
						rules: [{
							required: true,
							errorMessage: '请输入缴费类型',
						}, ]
					},
					payDay: {
						rules: [{
							required: true,
							errorMessage: '请输入收款日',
						}, ]
					},
					billName: {
						rules: [{
							required: true,
							errorMessage: '请输入账单名称',
						}, ]
					},
				}
			}
		},
		created() {
			// // window.localStorage.getItem('token', token)
			// this.token = window.localStorage.getItem('token')
		},
		computed: {},
		//初始化路径
		onLoad(val) {
			if (val.item != null) {
				const it = JSON.parse(decodeURIComponent(val.item));
				const type = JSON.parse(decodeURIComponent(val.name));
				this.paymentType.payee = it
				this.paymentType.type = type
				this.paymentType.userId = 1
			}

			// console.log("输出" + it)
			// for (var i in it) {
			// 	var obj = {
			// 		text: it[i].type,
			// 		tex1: it[i].ownerId,
			// 		tex2: it[i].tenantsId,
			// 		tex3: it[i].id,
			// 		tex4: it[i].account.payee,
			// 		tex5: it[i].user[i].account,
			// 	}
			// 	console.log("obj为" + this.obj)
			// }
			// this.paymentType.houseId = obj.tex3
			// this.paymentType.chargeId = obj.tex1
			// this.paymentType.type = obj.text
			// this.paymentType.payee = obj.tex2
			// this.paymentType.payee = obj.tex4
			// this.paymentType.account = obj.tex5
		},
		methods: {
			dianji() {
				this.paymentType.billNumber = Math.floor(Math.random() * 10000000000 + 1);
			},
			// 提交按钮
			submitForm() {
				this.$refs.form.validate().then(res => {
					console.log('表单数据信息：', res);
					this.$axios({
						url: '/systemuser/payment-type/cfInsertPayment',
						data: this.paymentType,
						method: 'POST',
						success: (res) => {
							if (res.data.code == 2000) {
								console.log(res.data)
								uni.showToast({
									title: '添加成功',
									icon: 'success'
								})
								uni.navigateTo({
									url: '../../livingexpenses/livingexpenses'
								})
							} else {
								uni.showToast({
									title: '添加失败',
									icon: 'error'
								})
							}
						}
					})
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},
		}
	}
</script>
<style>
	.content {
		margin-top: 60rpx;
	}

	.button-login {
		color: #FFFFFF;
		font-size: 34rpx;
		width: 470rpx;
		height: 100rpx;
		background: linear-gradient(-90deg, rgba(58, 163, 255, 1.0), rgba(255, 197, 131, 1.0));
		box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.2);
		border-radius: 50rpx;
		line-height: 100rpx;
		text-align: center;
		margin-left: auto;
		margin-right: auto;
		margin-top: 100rpx;
	}

	.button-hover {
		background: linear-gradient(-90deg, rgba(63, 205, 235, 0.8), rgba(188, 226, 158, 0.8));
	}

	.inputBox {
		display: flex;
		flex-direction: column;
		padding-top: 50rpx;
		padding-left: 70rpx;
		padding-right: 70rpx;
	}

	.button-zhuce {
		color: #ffa800;
		font-size: 34rpx;
		width: 200rpx;
		height: 10rpx;
		/* text-align: right; */
		margin-left: 230rpx;
		margin-top: 30rpx;
	}

	.dd {
		width: 230rpx;
		height: 50rpx;
		font-size: 10rpx;
		background-color: #DD6161;
		text-align: center;
	}
</style>
